<?php
/**
 * Created by PhpStorm.
 * User: syzhou
 * Date: 2020-11-12
 * Time: 18:36
 */

require_once __DIR__ . '/common.php';
require_once __DIR__ . '/file.php';

$srcHome = '/Users/syzhou/Downloads/upload';
$dstHome = __DIR__ . '/output/upload';

global $uploadedFilePathsSavePath;
$uploadedFilePaths = file($uploadedFilePathsSavePath, FILE_IGNORE_NEW_LINES);
$i = 1;
foreach ($uploadedFilePaths as $uploadedFilePath) {
    $uploadedFilePath = trim($uploadedFilePath, '/');
    $uploadedFilePathParts = explode('/', $uploadedFilePath);
    $level2Dir = $uploadedFilePathParts[1];
    $level3Dir = $uploadedFilePathParts[2];
    $srcDir = "$srcHome/$level2Dir/$level3Dir";
    $dstDir = "$dstHome/$level2Dir/$level3Dir";
    echo "$i. copying from '$srcDir' to '$dstDir'\n";
    $i++;
    $copyDirResultCode = copyDir($srcDir, $dstDir);
    if (0 != $copyDirResultCode) {
        echo "failed(result code: $copyDirResultCode). stop.";
        exit(-1);
    }
}